﻿/***************************************************/
/*** file:IMProtocal.cs                          ***/
/*** date:2010-08-07                             ***/
/*** author:huas                                 ***/
/*** function:implement IM protocol              ***/
/***************************************************/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace IM.Common
{
  
    [Flags]
    public enum InnerFlag : byte
    {
        INNERFLAG_NONE = 0,
        INNERFLAG_CLEAR_CLIENT = 1,    
        INNERFLAG_LOGIC_REQUEST_CLOSE_SOCKET = 2,
        INNERFLAG_NOTIFY_SOCKET_CLOSE = 4,
        INNERFLAG_HAVE_USER_DATA = 8,
        INNERFLAG_SET_USER_DATA = 16,  //
        INNERFLAG_REDISPATCH = 32,     //逻辑层要求imserver重新分发数据包
    }

    public struct NetHeader
    {
        public int m_nSocketIndex;
        public long m_createTime;
        public UInt32 m_uSocketCount;
        public InnerFlag m_nInnerFlag;
        public UInt64 m_nRecvPackCount; //接收的总包数
        public Int64 m_userData;        //给logic用的，设置自定义数据  

        public static readonly int SIZE = 
            sizeof(int) + sizeof(long) + sizeof(UInt32) + 
            sizeof(byte) + sizeof(UInt64) + sizeof(Int64);

        public void ToBytes(byte[] szBuffer, int nOffset)
        {
            //write m_nSocketIndex;
            byte[] szTemp = BitConverter.GetBytes(m_nSocketIndex);
            for (int i = 0; i < szTemp.Length; i++)
            {
                szBuffer[i + nOffset] = szTemp[i];
            }
            nOffset += szTemp.Length;
            //write m_createTime;
            szTemp = BitConverter.GetBytes(m_createTime);
            for (int i = 0; i < szTemp.Length; i++)
            {
                szBuffer[i + nOffset] = szTemp[i];
            }
            nOffset += szTemp.Length;
            //write m_uSocketCount;
            szTemp = BitConverter.GetBytes(m_uSocketCount);
            for (int i = 0; i < szTemp.Length; i++)
            {
                szBuffer[i + nOffset] = szTemp[i];
            }
            nOffset += szTemp.Length;
            //write m_innerFlag;
            szBuffer[nOffset] = (byte)m_nInnerFlag;
            nOffset += 1;
            //write m_nRecvPackCount
            szTemp = BitConverter.GetBytes(m_nRecvPackCount);
            for (int i = 0; i < szTemp.Length; i++)
            {
                szBuffer[i + nOffset] = szTemp[i];
            }
            nOffset += sizeof(UInt64);
            //write m_userData
            szTemp = BitConverter.GetBytes(m_userData);
            for (int i = 0; i < szTemp.Length; i++)
            {
                szBuffer[i + nOffset] = szTemp[i];
            }
        }

        public void FromBytes(byte[] szBuffer, int nOffset)
        {
            //read m_nSocketIndex;
            m_nSocketIndex = BitConverter.ToInt32(szBuffer, nOffset);
            nOffset += sizeof(int);
            //read m_createTime;
            m_createTime = BitConverter.ToInt64(szBuffer, nOffset);
            nOffset += sizeof(long);
            //read m_uSocketCount;
            m_uSocketCount = BitConverter.ToUInt32(szBuffer, nOffset);
            nOffset += sizeof(uint);
            //read m_innerFlag;
            m_nInnerFlag = (InnerFlag)szBuffer[nOffset];

            nOffset += sizeof(byte);
            //read m_uSocketCount;
            m_nRecvPackCount = BitConverter.ToUInt64(szBuffer, nOffset);

            nOffset += sizeof(UInt64);
            //read m_uSocketCount;
            m_userData = BitConverter.ToInt64(szBuffer, nOffset);

        }
    }

    public interface ISerial
    {
        void Load(ref BinaryReader reader);
        void Save(ref BinaryWriter writer);
    };

    public interface IProtocol
    {
        UInt16 ProtocolId
        {
            get;
        }
        byte[] ToBytes();
        void FromBytes(byte[] buffer);
    };

    public abstract class IMSerial : ISerial
    {
        public abstract void Load(ref BinaryReader reader);
        public abstract void Save(ref BinaryWriter writer);
        public byte[] ToBytes()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);
            Save(ref writer);
            writer.Close();
            return stream.GetBuffer();
        }
        public void FromBytes(byte[] buffer)
        {
            BinaryReader reader = new BinaryReader(new MemoryStream(buffer));
            Load(ref reader);
            reader.Close();
        }
        public static int WriteString(ref BinaryWriter writer, ref string str)
        {
            byte[] buf = Encoding.UTF8.GetBytes(str);
            int nBufLength = buf.Length;

            //先写入长度，再写入内容
            writer.Write(nBufLength);
            writer.Write(buf, 0, nBufLength);
            return buf.Length;
        }
        public static string ReadString(ref BinaryReader reader)
        {
            //读出字符串的长度
            int nStrLength = reader.ReadInt32();
            byte[] buf = reader.ReadBytes(nStrLength);
            return Encoding.UTF8.GetString(buf);
        }
    }

    public abstract class IMProtocolHead : IProtocol, ISerial
    {
        public UInt32 uDataLength;
        private UInt16 wProtocol;
        public UInt16 wVersion;
        public IMProtocolHead()
        {
            wProtocol = 0;
            wVersion = (UInt16)IMProtocolDef.im_version;
        }
        public virtual UInt16 ProtocolId
        {
            get { return wProtocol; }
            set { wProtocol = value; }
        }

        public virtual void Load(ref BinaryReader reader)
        {
            uDataLength = reader.ReadUInt32();
            wProtocol = reader.ReadUInt16();
            wVersion = reader.ReadUInt16();
        }
        public virtual void Save(ref BinaryWriter writer)
        {
            writer.Write(uDataLength);
            writer.Write(wProtocol);
            writer.Write(wVersion);
        }
        public abstract void Init();
       
        public virtual byte[] ToBytes()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);
            Save(ref writer);
            
            //写入包长度,放在这里很别扭，有比较好的方法吗?
            uDataLength =  (uint)stream.Length;
            writer.Seek(0, SeekOrigin.Begin);
            writer.Write(uDataLength);

            byte[] buffer = stream.GetBuffer();
            Array.Resize(ref buffer, (int)stream.Length);            
            
            writer.Close();
            stream.Close();
            return buffer;
        }
        public virtual void FromBytes(byte[] buffer)
        {
            BinaryReader reader = new BinaryReader(new MemoryStream(buffer));
            Load(ref reader);
            reader.Close();
        }
    };

    //用户登录协议
    public class c2s_account_verify : IMProtocolHead
    {
        public string szAccount;         //账号
        public string szPassword;        //密码
        public byte   uAccountStatus;    //账号状态

        public c2s_account_verify()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_c2s_account_verify;
        }
        public override void Init()
        {
            uAccountStatus = (byte)IMAccountStatus.im_status_online;
            szPassword = string.Empty;
            szAccount = string.Empty;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szAccount = IMSerial.ReadString(ref reader);

            szPassword = IMSerial.ReadString(ref reader);
            uAccountStatus = reader.ReadByte();
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szAccount);
            IMSerial.WriteString(ref writer, ref szPassword);
            writer.Write(uAccountStatus);
        }

    };

    //用户登录结果协议
    public class s2c_account_verify_result : IMProtocolHead
    {
        public string szAccount;         //账号，
        public string szPetName;         //昵称，
        
        public int   nGrade;               //等级,
        public string szLastLoginIP;     //上次登录IP,
        public string szMotto;           //个性签名，

        public int nSex;                //性别 0, man 1 woman
        public int nYear;                //生日的年份
        public int nMonth;              //生日的月份
        public int nDay;                //生日的天
        public int nAge;                //年龄

        public string szXiaoSheng;        //生肖  
        public string szStar;             //星座 
        public string szBlood;            //血型    

        public string szCountry;          //国家 
        public string szProvince;         //省份 
        public string szCity;             //城市  

        public int nVerifyResult;        //验证结果，1 ok
                                         //

        public s2c_account_verify_result()
        {
            Init();
        }
        //初始化
        public override void Init()
        {
            ProtocolId = (ushort)IMProtocolDef.im_s2c_account_verify_result;

            szAccount = string.Empty;
            szPetName = string.Empty;

            nGrade = 0;
            szLastLoginIP = string.Empty;
            szMotto = string.Empty; 
          
            nSex = 0;               
            nYear = 0;              
            nMonth = 0;             
            nDay = 0;               
            nAge = 0;

            szXiaoSheng = string.Empty;
            szStar = string.Empty;
            szBlood = string.Empty;

            szCountry = string.Empty;
            szProvince = string.Empty;
            szCity = string.Empty;

            nVerifyResult = -1;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szAccount = IMSerial.ReadString(ref reader);
            szPetName = IMSerial.ReadString(ref reader);

            nGrade = reader.ReadInt32();
            szLastLoginIP = IMSerial.ReadString(ref reader);
            szMotto = IMSerial.ReadString(ref reader);

            nSex = reader.ReadInt32();
            nYear = reader.ReadInt32();
            nMonth = reader.ReadInt32();
            nDay = reader.ReadInt32();
            nAge = reader.ReadInt32();

            szXiaoSheng = IMSerial.ReadString(ref reader);
            szStar = IMSerial.ReadString(ref reader);
            szBlood = IMSerial.ReadString(ref reader);

            szCountry = IMSerial.ReadString(ref reader);
            szProvince = IMSerial.ReadString(ref reader);
            szCity = IMSerial.ReadString(ref reader);
            nVerifyResult = reader.ReadInt32();
            
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szAccount);
            IMSerial.WriteString(ref writer, ref szPetName);

            writer.Write(nGrade);
            IMSerial.WriteString(ref writer, ref szLastLoginIP);
            IMSerial.WriteString(ref writer, ref szMotto);
            writer.Write(nSex);
            writer.Write(nYear);
            writer.Write(nMonth);
            writer.Write(nDay);
            writer.Write(nAge);

            IMSerial.WriteString(ref writer, ref szXiaoSheng);
            IMSerial.WriteString(ref writer, ref szStar);
            IMSerial.WriteString(ref writer, ref szBlood);
            IMSerial.WriteString(ref writer, ref szCountry);
            IMSerial.WriteString(ref writer, ref szProvince);
            IMSerial.WriteString(ref writer, ref szCity);
    
            writer.Write(nVerifyResult);
        }

    };

    //用户登出协议
    public class c2s_account_logout : IMProtocolHead
    {
        public string szAccount;         //账号
        public int nLogoutReason;        //退出原因(0,正常登出。2,其它原因)

        public c2s_account_logout()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_c2s_account_logout;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szAccount = IMSerial.ReadString(ref reader);
            nLogoutReason = reader.ReadInt32();
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szAccount);
            writer.Write(nLogoutReason);
        }

        public override void Init()
        {
            szAccount = string.Empty;
            nLogoutReason = 0;
        }
    };

    //服务器端通知用户退出协议
    public class s2c_account_logout : IMProtocolHead
    {
        public string szAccount;         //账号
        public int nLogoutReason;        //退出原因
                                         //(err_im_account_login_other)

        public s2c_account_logout()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_s2c_account_logout_result;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szAccount = IMSerial.ReadString(ref reader);
            nLogoutReason = reader.ReadInt32();
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szAccount);
            writer.Write(nLogoutReason);
        }
        public override void Init()
        {
            szAccount = string.Empty;
            nLogoutReason = 0;
        }
    };

    //用户 请求改变状态
    public class c2s_change_account_Status : IMProtocolHead
    {
        public string szAccount;               //账号
        public byte bStatus;                  //用户状态
       
        public c2s_change_account_Status()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_s2c_notify_account_Status;
        }

        public override void Init()
        {
            szAccount = string.Empty;
            bStatus = 0;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szAccount = IMSerial.ReadString(ref reader);
            bStatus = reader.ReadByte();
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szAccount);
            writer.Write(bStatus);
        }

    };
    //服务器端广播用户状态（广播消息）
    public class s2c_notify_account_Status : IMProtocolHead
    {
        public string szAccount;               //账号
        public byte bStatus;                  //用户状态
        //(err_im_account_login_other)

        public s2c_notify_account_Status()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_s2c_notify_account_Status;
        }

        public override void Init()
        {
            szAccount = string.Empty;
            bStatus = 0;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szAccount = IMSerial.ReadString(ref reader);
            bStatus = reader.ReadByte();
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szAccount);
            writer.Write(bStatus);
        }

    };

    //用户聊天协议
    public class c2s_account_chat : IMProtocolHead
    {
        public string szAccount;               //账号，
        public byte   bFontSize;               //字体大小
        public byte   bFontStyle;              //字体样式，由客户端定义
        public byte   bR;                      //RGB,颜色
        public byte   bG;
        public byte   bB;
        public string szCharset;              //字符集
        public string szContent;              //聊天内容

        public c2s_account_chat()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_c2s_account_chat;
        }
        public override void Init()
        {
            szAccount = string.Empty;
            bFontSize = 0;
            bFontStyle = 0;
            bR = bG = bB = 0;
            szCharset = string.Empty;
            szContent = string.Empty;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szAccount = IMSerial.ReadString(ref reader);
            bFontSize = reader.ReadByte();
            bFontStyle = reader.ReadByte();
            bR = reader.ReadByte();
            bG = reader.ReadByte();
            bB = reader.ReadByte();
            szCharset = IMSerial.ReadString(ref reader);
            szContent = IMSerial.ReadString(ref reader);
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szAccount);
            writer.Write(bFontSize);
            writer.Write(bFontStyle);
            writer.Write(bR);
            writer.Write(bG);
            writer.Write(bB);
            IMSerial.WriteString(ref writer, ref szCharset);
            IMSerial.WriteString(ref writer, ref szContent);
        }

    };

    //接收到用户聊天协议
    public class s2c_account_chat : IMProtocolHead
    {
        public string szAccount;           //账号，目标账号
        public byte bFontSize;               //字体大小
        public byte bFontStyle;              //字体样式，由客户端定义
        public byte bR;                      //RGB,颜色
        public byte bG;
        public byte bB;
        public string szCharset;              //字符集
        public string szContent;              //聊天内容

        public s2c_account_chat()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_s2c_account_chat;
        }
        public override void Init()
        {
            szAccount = string.Empty;
            bFontSize = 0;
            bFontStyle = 0;
            bR = bG = bB = 0;
            szCharset = string.Empty;
            szContent = string.Empty;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szAccount = IMSerial.ReadString(ref reader);
            bFontSize = reader.ReadByte();
            bFontStyle = reader.ReadByte();
            bR = reader.ReadByte();
            bG = reader.ReadByte();
            bB = reader.ReadByte();
            szCharset = IMSerial.ReadString(ref reader);
            szContent = IMSerial.ReadString(ref reader);
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szAccount);
            writer.Write(bFontSize);
            writer.Write(bFontStyle);
            writer.Write(bR);
            writer.Write(bG);
            writer.Write(bB);
            IMSerial.WriteString(ref writer, ref szCharset);
            IMSerial.WriteString(ref writer, ref szContent);
        }

    };

    //添加好友协议
    public class c2s_add_account : IMProtocolHead
    {
        public string szSrcAccount;            //账号，源账号
        public string szDestAccount;           //账号，好友
        public string szGroupName;                   //好友所在的分组

        public c2s_add_account()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_c2s_add_account;
        }
        public override void Init()
        {
            szSrcAccount = string.Empty;
            szDestAccount = string.Empty;
            szGroupName = string.Empty;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szSrcAccount = IMSerial.ReadString(ref reader);
            szDestAccount = IMSerial.ReadString(ref reader);
            szGroupName = IMSerial.ReadString(ref reader);
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szSrcAccount);
            IMSerial.WriteString(ref writer, ref szDestAccount);
            IMSerial.WriteString(ref writer, ref szGroupName);
        }
    };

    //添加好友结果协议
    public class s2c_add_account_result : IMProtocolHead
    {
        public string szSrcAccount;            //账号，源账号
        public string szDestAccount;           //账号，好友
        public string szGroupName;                   //好友所在的分组
        public int nAddAccountResult;          //结果

        public s2c_add_account_result()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_s2c_add_account_result;
        }
        public override void Init()
        {
            szSrcAccount = string.Empty;
            szDestAccount = string.Empty;
            szGroupName = string.Empty;
            nAddAccountResult = 0;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szSrcAccount = IMSerial.ReadString(ref reader);
            szDestAccount = IMSerial.ReadString(ref reader);
            szGroupName = IMSerial.ReadString(ref reader);
            nAddAccountResult = reader.ReadInt32();
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szSrcAccount);
            IMSerial.WriteString(ref writer, ref szDestAccount);
            IMSerial.WriteString(ref writer, ref szGroupName);
            writer.Write(nAddAccountResult);
        }
    };

    //删除好友协议
    public class c2s_delete_account : IMProtocolHead
    {
        public string szSrcAccount;            //账号，源账号
        public string szDestAccount;           //账号，好友
        public string szGroupName;                   //好友所在的分组

        public c2s_delete_account()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_c2s_delete_account;
        }
        public override void Init()
        {
            szSrcAccount = string.Empty;
            szDestAccount = string.Empty;
            szGroupName = string.Empty;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szSrcAccount = IMSerial.ReadString(ref reader);
            szDestAccount = IMSerial.ReadString(ref reader);
            szGroupName = IMSerial.ReadString(ref reader);
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szSrcAccount);
            IMSerial.WriteString(ref writer, ref szDestAccount);
            IMSerial.WriteString(ref writer, ref szGroupName);
        }
    };
    //删除好友结果协议
    public class s2c_delete_account_result : IMProtocolHead
    {
        public string szSrcAccount;            //账号，源账号
        public string szDestAccount;           //账号，好友
        public string szGroupName;                   //好友所在的分组
        public int nDeleteAccountResult;          //结果

        public s2c_delete_account_result()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_s2c_delete_account_result;
        }
        public override void Init()
        {
            szSrcAccount = string.Empty;
            szDestAccount = string.Empty;
            szGroupName = string.Empty;
            nDeleteAccountResult = 0;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szSrcAccount = IMSerial.ReadString(ref reader);
            szDestAccount = IMSerial.ReadString(ref reader);
            szGroupName = IMSerial.ReadString(ref reader);
            nDeleteAccountResult = reader.ReadInt32();
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szSrcAccount);
            IMSerial.WriteString(ref writer, ref szDestAccount);
            IMSerial.WriteString(ref writer, ref szGroupName);
            writer.Write(nDeleteAccountResult);
        }
    };

    //增加分组协议
    public class c2s_add_group : IMProtocolHead
    {
        public string szSrcAccount;            //账号，源账号
        public string szGroupName;             //组名

        public c2s_add_group()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_c2s_add_group;
        }
        public override void Init()
        {
            szSrcAccount = string.Empty;
            szGroupName = string.Empty;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szSrcAccount = IMSerial.ReadString(ref reader);
            szGroupName = IMSerial.ReadString(ref reader);
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szSrcAccount);
            IMSerial.WriteString(ref writer, ref szGroupName);
        }
    };
    //增加分组结果协议
    public class s2c_add_group_result : IMProtocolHead
    {
        public string szSrcAccount;            //账号，源账号
        public string szGroupName;                   //好友所在的分组
        public int nAddGroupResult;          //结果

        public s2c_add_group_result()
        {
            Init();
            ProtocolId = (ushort)IMProtocolDef.im_s2c_add_group_result;
        }
        public override void Init()
        {
            szSrcAccount = string.Empty;
            szGroupName = string.Empty;
            nAddGroupResult = 0;
        }
        public override void Load(ref BinaryReader reader)
        {
            base.Load(ref reader);
            szSrcAccount = IMSerial.ReadString(ref reader);
            szGroupName = IMSerial.ReadString(ref reader);
            nAddGroupResult = reader.ReadInt32();
        }
        public override void Save(ref BinaryWriter writer)
        {
            base.Save(ref writer);
            IMSerial.WriteString(ref writer, ref szSrcAccount);
            IMSerial.WriteString(ref writer, ref szGroupName);
            writer.Write(nAddGroupResult);
        }
    };


    public enum IMProtocolDef {
        im_version = 10,             //1.0版
	    im_c2s_account_verify = 11,        //用户登录协议
        im_s2c_account_verify_result = 12, //用户登录结果

        im_c2s_account_logout = 13,        //用户登出
        im_s2c_account_logout_result = 14, //

        im_c2s_change_account_Status = 15, //用户请求改变状态
        im_s2c_notify_account_Status = 16, //

        im_c2s_account_chat = 17,        //聊天消息协议
        im_s2c_account_chat = 18,        //聊天消息协议

        im_c2s_add_account  = 19,        //增加好友协议
        im_s2c_add_account_result = 20,   //增加好友结果协议

        im_c2s_delete_account = 21,      //删除好友协议
        im_s2c_delete_account_result = 22, //删除好友结果协议

        im_c2s_add_group = 23,        //增加分组协议
        im_s2c_add_group_result = 24, //删除分组协议
    };
    public enum IMAccountStatus { 
        im_status_online    = 1,
        im_status_hidden    = 2,
        im_status_leave     = 3,
        im_status_busy      = 4,
        im_status_offline   = 5,
        im_status_notrouble = 6,
    }
    public enum IMResult {
        im_success = 1,
        //登录、退出相关
	    err_im_full = 1001 ,          //服务器已经满  
        err_im_account_or_pwd,        //账号或密码错误
        err_im_account_login_other,   //账号已经在别的地方登录了
        im_account_normal_logout  , //用户正常退出

        //其它协议错误码
    };
}
